package com.numberone.web.controller.coupon;

import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.Coupon;
import com.numberone.system.domain.CouponUser;
import com.numberone.system.service.ICouponService;
import com.numberone.system.service.ICouponUserService;
import com.numberone.system.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/api/couponUser")
public class CouponUserApiController extends BaseController {
    @Autowired
    private ICouponUserService couponUserService;

    /**
     * 获取用户已领取优惠券列表
     * @param userId
     * @return
     */
    @ResponseBody
    @PostMapping("/getUserCoupon")
    public Object getUserCoupon(Long userId)
    {
        CouponUser couponUser = new CouponUser();
        couponUser.setUserId(userId);
        List<CouponUser> couponUsers = couponUserService.selectCouponUserList(couponUser);
        return JsonResult.success(couponUsers);
    }

    /**
     * 领取优惠券
     * @param couponUser
     * @return
     */
    @ResponseBody
    @PostMapping("/addUserCoupon")
    public Object addUserCoupon(CouponUser couponUser)
    {
        int i = couponUserService.insertCouponUser(couponUser);
        if (i > 0)
        {
            return JsonResult.success();
        }else
        {
            return JsonResult.nodata();
        }
    }
}
